<?php


namespace App\HttpController;


use EasySwoole\Http\AbstractInterface\Controller;

class Index extends Controller
{

    public function index()
    {
        $file = EASYSWOOLE_ROOT.'/vendor/easyswoole/easyswoole/src/Resource/Http/welcome.html';
        if(!is_file($file)){
            $file = EASYSWOOLE_ROOT.'/src/Resource/Http/welcome.html';
        }
        $this->response()->write(file_get_contents($file));
    }

    function test()
    {
        $this->response()->write('this is test');
    }

    protected function actionNotFound(?string $action)
    {
        $this->response()->withStatus(404);
        $file = EASYSWOOLE_ROOT.'/vendor/easyswoole/easyswoole/src/Resource/Http/404.html';
        if(!is_file($file)){
            $file = EASYSWOOLE_ROOT.'/src/Resource/Http/404.html';
        }
        $this->response()->write(file_get_contents($file));
    }

    public function try()
    {
        $instance = \EasySwoole\EasySwoole\Config::getInstance();

        // 获取配置 按层级用点号分隔
        $instance->getConf('MAIN_SERVER.SETTING.task_worker_num');

        // 设置配置 按层级用点号分隔
        // $instance->setConf('DATABASE.host', 'localhost');

        // 获取全部配置
        $conf = $instance->getConf();
        var_dump($conf);
    }
}